const fs = require('fs');
const path = require('path');
const pump = require('mz-modules/pump');
const BaseController = require('../core/baseController')

class UploadController extends BaseController {
    async upload() {
        const {ctx, config} = this
        const stream = await ctx.getFileStream();
        const filename = stream.filename
        const target = path.join(config.baseDir, `app/public/images/${filename}`)
        const writeStream = fs.createWriteStream(target)
        await pump(stream, writeStream)
        this.success({url: `http://www.senlingadmin.cn:7001/public/images/${filename}`})
    }

}

module.exports = UploadController
